import { defineStore } from "pinia";
import { ref } from "vue";
import i18n from "@/locales";
export const useLocaleStore = defineStore(
  "locale",
  () => {
    let locale = ref(i18n.global.locale.value);
    let theme = ref("default");
    let isMob = ref(false);
    let userid=ref("");
    let userName=ref("");
    let activeIndex=ref("");
    let dictionary=ref({});//全局字典
    let mainColor = ref([
      "#8fb13d",
      "#f56c6c",
      "#58919f",
      "#fac858",
      "#73c0de",
      "#3ba272",
      "#fc8452",
      "#9a60b4",
      "#ea7ccc",
    ]);
    //let mainColor=ref(['#8fb13d','#d2853c','#62359a','#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc'])

    // 设置locale
    function setAuth(token:string){
        
      localStorage.setItem("token",token)
   }
    function setLocale(lang: any) {
      locale.value = lang;
      i18n.global.locale.value = lang;
    }
    function setTheme(skin: string) {
      theme.value = skin;
    }
    function setIsMob(bool: boolean) {
      isMob.value = bool;
    }
    function setMainColor(data: any) {
      mainColor.value = data;
    }
    function setUserid(data: string) {
      userid.value = data;
    }
    function setActiveIndex(str: string) {
      activeIndex.value = str;
    }
    function setUserName(data: string) {
      userName.value = data;
    }
    function setDictionary(data: any) {
      dictionary.value = data;
    }
    return {
      locale,
      theme,
      isMob,
      mainColor,
      userid,
      userName,
      activeIndex,
      dictionary,
      setLocale,
      setTheme,
      setIsMob,
      setMainColor,
      setUserid,
      setActiveIndex,
      setUserName,
      setAuth,
      setDictionary
    };
  },
  {
    persist: {
      key: "baseStore", //存储名称
      storage: localStorage, // 存储方式
      paths: ["locale", "theme", "mainColor","userid","userName","activeIndex","dictionary"],
    },
  }
);
